<?php
//------------------------------------------------------------------------------
// Class              : Ctl_Info
// Modification       :
//------------------------------------------------------------------------------
// Date(yyyy.mm.dd)   Developer                       Action
//------------------------------------------------------------------------------
// 2008.01.21          Dang Thanh                         Created
//------------------------------------------------------------------------------

class Ctl_Info extends ControlBase{
    var $modul="info";
    //==========================================================================
    // Function    : Ctl_Info
    // Creator     : NgocVQ 2007.03.15
    // Details     : Call the constructor of father class to initial variable
    //==========================================================================
    function Ctl_Info(){
         // Constructor of father class.
         ControlBase::ControlBase();
    }

    //==========================================================================
    // Function    : execute
    // Creator     : NgocVQ 2007.03.15
    // Details     : Execute the process depend the given mode, 
    //               as: Add, Delete, Edit and default is List.
    //==========================================================================
     function execute($action=""){
        global $db, $arrayError, $_POST;
        $arrayData =  array();
        // Get back the work you want to do.
        $this->modul = CM_getParameter(MODUL);
        if ($action==""){
            // Get back the action: as: Add, Delete, Edit or List.
             $action = CM_getParameter(ACTION);
        }
        
        // Get data
        include_once(DIR_MODEL."md_info.class.php");
        $objInfo = new MD_Info($this->db);
		include_once(DIR_MODEL."md_function.class.php");
		$objFunction = new MD_Function($this->db);
		include_once(DIR_MODEL."md_content.class.php");
		$objContent = new MD_Content($this->db);
        switch($action){  
			 case "SearchText":
			  	$arrayDataInfo = array();
				$arrayDataContent = array();
			 	$key_search = isset($_POST['txtkeySearch'])?$_POST['txtkeySearch']:(isset($_SESSION['txtkeySearch'])?$_SESSION['txtkeySearch']:"");
				$page = (isset($_GET["curPage"]) && is_numeric($_GET["curPage"]))?$_GET["curPage"]:1;
				$_SESSION['txtkeySearch'] = $key_search;
				$arrayDataInfo = $objInfo->getForSearchText($key_search);
				
				include_once(DIR_VIEW."v_list_search.php");
				V_ListSearch($arrayDataInfo, $arrayDataContent, $action);
			 	break;
				
			 case "View":
                 // Get a record with given id
                 $id = CM_getParameter("id");
                 $arrayData = $objInfo->getById($id);
                 // Show data
				 $id_loai = CM_getParameter("id_loai");; 
				 $arrayDataFn = $objFunction->getById2($id_loai);
				 $FnName1 = $arrayDataFn["function_name"];
				 
				 $strWhere = 'id_loai = '.$id_loai.' and id <> '.$id;
				 $strOrder = ' ordering asc  ';
				 $arrayData1 = $objInfo->getByWhere('*',$strWhere,$strOrder);
				
                 include_once(DIR_VIEW."v_info_view.php");                   
                 V_InfoView(&$FnName1, &$arrayData, &$arrayData1);
                 // update SoLanXem + 1
                $objInfo->updateSoLanXem($id);       
                 break; 
				 
			case "List":
				$id_loai = CM_getParameter("id_loai"); 
				if($id_loai==3) $id_loai=8;
					/*$arrayDataFn = $objFunction->getById2($id_loai);
					$FnName1 = $arrayDataFn["function_name"];
					$arrayDataFn = $objFunction->getById2('8');
					$FnName2 = $arrayDataFn["function_name"];
					$arrayDataFn = $objFunction->getById2('9');
					$FnName3 = $arrayDataFn["function_name"];
					$strWhere = 'id_loai = 8';
					$strOrder = ' ordering asc ';
					$arrayData1 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,noi_dung,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
					$strWhere = 'id_loai = 9 ';
					$arrayData2 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,noi_dung,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
					// Error processing
					 if(empty($arrayData1)){
						$arrayError[]=$LANG["error"]["khong_tim_thay_ban_ghi"];//"Không tìm thấy bản ghi.";// nào có id=".$id;
					 }
					 // Show data
					 include_once(DIR_VIEW."v_info_list2.php");                   
					 V_InfoList2(&$FnName1,&$FnName2,&$FnName3,&$arrayData1,&$arrayData2);
				}else{*/
					$arrayDataFn = $objFunction->getById2($id_loai);
					$FnName1 = $arrayDataFn["function_name"];
					$strWhere = 'id_loai = '.$id_loai.' ';
					$strOrder = ' ordering asc ';
					$arrayData1 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,noi_dung,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
								 
					// Error processing
					 if(empty($arrayData1)){
						$arrayError[]=$LANG["error"]["khong_tim_thay_ban_ghi"];//"Không tìm thấy bản ghi.";// nào có id=".$id;
					 }
					 // Show data
					 $this->includeFileLang("l_info_view.php");	
					 include_once(DIR_VIEW."v_info_list.php");                   
					 V_InfoList(&$FnName1, &$arrayData1);
				//}       
                break;      
			default :{
				//SEVICES
				$id_loai = 8; 
				$arrayDataFn = $objFunction->getById2($id_loai);
				$FnName1 = $arrayDataFn["function_name"];
				$strWhere = 'id_loai = '.$id_loai.' ';
				$strOrder = ' ordering asc ';
                $arrayData1 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
				
				 //SOLUTIONS
				 $id_loai = 9; 
				 $arrayDataFn = $objFunction->getById2($id_loai);
				 $FnName2 = $arrayDataFn["function_name"];
				 $strWhere = 'id_loai = '.$id_loai.' ';
				 $arrayData2 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
				 
				 //PRODUCTS
				$id_loai = 10; 
				$arrayDataFn = $objFunction->getById2($id_loai);
				$FnName3 = $arrayDataFn["function_name"];
				$strWhere = 'id_loai = '.$id_loai.' ';
				$strOrder = ' ordering asc ';
                $arrayData3 = $objInfo->getByWhere("id,id_loai,tieu_de,tom_tat,ten_anh,so_lan_xem,ngay_tao,ngay_cap_nhat", $strWhere, $strOrder);
				
				//NEWS
				$id_loai = 6; 
				$arrayDataFn = $objFunction->getById2($id_loai);
				$FnName4 = $arrayDataFn["function_name"];
				$strWhere = 'cat_id = '.$id_loai.' and shows = 1 ';
				$strOrder = ' created_date desc ';
				$arrayData4 = $objContent->getByWhere('*',$strWhere,$strOrder);
				
                // Error processing
                 if(empty($arrayData1) || empty($arrayData2) || empty($arrayData3) || empty($arrayData4)){
                    $arrayError[]=$LANG["error"]["khong_tim_thay_ban_ghi"];//"Không tìm thấy bản ghi.";// nào có id=".$id;
                 }
                 // Show data
                 include_once(DIR_VIEW."v_home.php");
                 V_Home(&$FnName1, &$arrayData1, &$FnName2, &$arrayData2, &$FnName3, &$arrayData3, &$FnName4, &$arrayData4);
                 // update SoLanXem + 1
              //  $objInfo->updateSoLanXem($id);       
                 break; 
			}            
        }
        unset($arrayDataFn,$arrayData1,$arrayData2,$arrayData4,$arrayData5);
    }      
} 
?>